package org.ax.websocket;

import org.ax.pojo.sys.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.Mapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

import javax.servlet.http.HttpSession;

/**
 * 编程人:赵浩鑫
 * 时间:2021-02-22-09:47
 */

@Component
@EnableWebSocket
@Controller
public class NzWebSocketConfig extends WebMvcConfigurationSupport implements WebSocketConfigurer {
    /**
     * 当WebSocketHandler类被加载时就会创建该Integer，随类而生
     * 测试用的，用于分辨
     */
    public static Integer count = 0;

    /**
     * 跳转到聊天View
     * @param session
     * @return
     */
    @Autowired
    NzWebSocketHandler handler;

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry webSocketHandlerRegistry) {

        //添加websocket处理器，添加握手拦截器
        webSocketHandlerRegistry.addHandler(handler, "/ListMap/websocket").addInterceptors(new NzHandShakeInterceptor());

    }

}
